/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package intelligenttm.InPutDlg;

import intelligenttm.ITMCarto.BaseData;
import intelligenttm.SourceFile.RibbonShow;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.MenuButton;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import me.aviator.entity.HibernateUtil;
import me.aviator.entity.Ribbon;
import me.aviator.service.impl.RibbonService;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

/**
 * FXML Controller class
 *
 * @author 望舒凌霄
 */
public class ChangeFenQuController implements Initializable {
    @FXML
    private AnchorPane RootPane;
    @FXML
    private Button BtnCancel;
    @FXML
    private Button BtnEnsure;
    @FXML
    private TableView<RibbonShow> TableRibbonShow;
    @FXML
    private TableColumn<RibbonShow, HBox> TCRibbonShow;
    @FXML
    private CheckBox ChBIs3D;
    @FXML
    private MenuButton MenuType;

    private String FenQuType="饼状图";
    boolean Is3D=false;
    private ObservableList<RibbonShow> RibbonShowList =  FXCollections.observableArrayList();
    private RibbonService ribbonService;
    private List<Ribbon> RList=new ArrayList<>();
    private Ribbon RibbonColor=null;
    private int LevelNum=0;
    private Map<String,String> conditions;
    private int WhichBtn=0;
    @FXML
    private MenuItem BingZhuangItem;
    @FXML
    private MenuItem TiaoXingItem;
    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
        SessionFactory sf=HibernateUtil.getSessionFactory();
        Session sess=sf.openSession();
        Transaction tx=sess.beginTransaction();
        conditions=new HashMap<>();
        ribbonService=new RibbonService(sess);
        TCRibbonShow.setCellValueFactory(new PropertyValueFactory<>("CHB"));
    }    

    public void SetRibbonLevel(int count){
        LevelNum=count;
        RList.clear();
        RList=ribbonService.ListByNum(LevelNum);
        //记得判断是否非空；
        if(!RList.isEmpty()){
            RibbonShowList.clear();
            for (int i=0;i<RList.size();i++){
                RibbonShow RS=new RibbonShow(RList.get(i));
                RibbonShowList.add(RS);
            }
            TableRibbonShow.setItems(RibbonShowList);
            TableRibbonShow.getSelectionModel().select(0);
            RibbonColor=RList.get(TableRibbonShow.getSelectionModel().getSelectedIndex());
        }
    }
    
    @FXML
    private void HandleBtnCancel(ActionEvent event) {
        WhichBtn=0;
        RootPane.getScene().getWindow().hide();
    }

    @FXML
    private void HandleBtnEnsure(ActionEvent event) {
        int Index=TableRibbonShow.getSelectionModel().getFocusedIndex();
        if(Index<0){
            Index=0;
        }
        RibbonColor=RList.get(Index);
        WhichBtn=1;
        RootPane.getScene().getWindow().hide();
    }

    @FXML
    private void HandleTableRibbonShow(MouseEvent event) {
    }

    @FXML
    private void HandleChBIs3D(ActionEvent event) {
        Is3D=ChBIs3D.isSelected();
    }

    @FXML
    private void HandleBingZhuangItem(ActionEvent event) {
        FenQuType="饼状图";
        MenuType.setText(FenQuType);
    }

    @FXML
    private void HandleTiaoXingItem(ActionEvent event) {
        FenQuType="条形图";
        MenuType.setText(FenQuType);
    }

    public String getFenQuType() {
        return FenQuType;
    }

    public void setFenQuType(String FenQuType) {
        this.FenQuType = FenQuType;
    }

    public boolean isIs3D() {
        return Is3D;
    }

    public void setIs3D(boolean Is3D) {
        this.Is3D = Is3D;
    }

    public Ribbon getRibbonColor() {
        return RibbonColor;
    }

    public void setRibbonColor(Ribbon RibbonColor) {
        this.RibbonColor = RibbonColor;
    }
    
    
    
}
